package com.tess.tboot.serviceimpl;

import com.tess.tboot.base.TbootServiceImpl;
import com.tess.tboot.dao.mapper.RoleMapper;
import com.tess.tboot.entity.Role;
import com.tess.tboot.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 角色接口实现
 * @author Exrickx
 */
@Slf4j
@Service
@Transactional
public class RoleServiceImpl extends TbootServiceImpl<RoleMapper,Role> {

    @Autowired
    private RoleMapper roleMapper;

    public List<Role> findByDefaultRole(Boolean defaultRole) {
        return roleMapper.findByDefaultRole(defaultRole);
    }

    public Page<Role> findWithPage(Map<String, Object> params, Pageable pageable) {

        int count = roleMapper.findByCond(params);
        Page<Role> page = new PageImpl<>(roleMapper.findByCondWithPage(params,new RowBounds(pageable.getPageNumber(),pageable.getPageSize())),pageable,count);

        return page;

    }
}
